<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../") ; }
 Include ("../../include/garennes.cfg") ;
 Include ("../../include/init.php") ;
 Include ("../include/config.inc") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 $valider = var_courante ("valider", 0, null) ;
 $id_memo_note = var_courante ("id_memo_note", 0, null) ;
 $id_utilisateur = var_courante ("id_utilisateur", 0, 0) ;
 $id_eleve = var_courante ("id_eleve", 0, 0) ;
 $repere1 = var_courante ("repere1", 0, "") ;
 $repere2 = var_courante ("repere2", 0, "") ;
 $texte = var_courante ("texte", 0, "") ;
 $retour = var_courante ("retour", 0, "travail.php") ;
 $id_eleve = var_courante ("id_eleve", 0, 0) ;
 $id_service_prof = var_courante ("id_service_prof", 0, 0) ;
 $eleve = var_courante ("eleve", 0, 0) ;
 $millesime = millesime (0) ;
 
 $param_theme = parametres_theme (themeparsession ($_SESSION ["code"])) ;
 $rep_themes = "../../images/themes/" ;
 Include ($rep_themes.$param_theme ["nom_repertoire"]."/".$param_theme ["fichier_config"]) ;
 
 If (IsSet ($valider))
  {
   If ($valider == "VaLiDeR")
    {
     If ($id_memo_note != 0)
      {
       If (($texte == "") Or ($texte == "<br/"))
        {
         // Destruction
         $requete = "DELETE FROM memo_notes WHERE id_memo_note='".$id_memo_note."' LIMIT 1" ;
        }
       Else
        {
         // Mise a jour
         $requete = "UPDATE memo_notes SET texte='".filtrage ($texte)."' WHERE id_memo_note='".$id_memo_note."' LIMIT 1" ;
        }
      }
     Else
      {
       // Nouvelle note
       $requete = "INSERT INTO memo_notes (id_memo_note,id_utilisateur,id_eleve,repere1,repere2,texte,millesime) VALUES " ;
       $requete .= "('','".$id_utilisateur."','".$id_eleve."','".$repere1."','".$repere2."','".filtrage ($texte)."','".$millesime."')" ;
      }
     $ok = SQL_commande ($requete, $id_sql) ;
     Echo "<HTML><BODY><SCRIPT> window.open(\"".$retour."?id_eleve=".$id_eleve."&id_classe=".$id_classe."&id_service_prof=".$id_service_prof ;
     Echo "&eleve=".$eleve."\",\"travail_affichage\") ; window.close() </SCRIPT></BODY></HTML>" ;
     //Echo "<HTML><BODY><SCRIPT> window.close() </SCRIPT></BODY></HTML>" ;
     Exit ;
    }
   ElseIf ($valider == "SuPpRiMeR")
    {
     $ok = SQL_commande ("DELETE FROM memo_notes WHERE id_memo_note='".$id_memo_note."' LIMIT 1", $id_sql) ;
     Echo "<HTML><BODY><SCRIPT> window.open(\"".$retour."?id_eleve=".$id_eleve."&id_classe=".$id_classe."&id_service_prof=".$id_service_prof ;
     Echo "&eleve=".$eleve."\",\"travail_affichage\") ; window.close() </SCRIPT></BODY></HTML>" ;
    }
  }
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0'", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ; 
 
 Echo "<HTML><HEAD>" ;
 entete_html ("Garennes - M&eacute;mo notes", "", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 Include ("./memo_notes.js") ;
 Echo "</HEAD>" ;
 
 $resultats = SQL_commande ("SELECT * FROM eleves WHERE id_eleve='".$id_eleve."' LIMIT 1", $id_sql) ;
 $ligne = SQL_tableau_associatif ($resultats, "") ;
 
 $nom_eleve = Str_Replace (" ", "&nbsp;", $ligne ["nom"]) ;
 If (StrPos ($ligne ["prenoms"], " ")) { $prenom = SubStr ($ligne ["prenoms"], 0, StrPos ($ligne ["prenoms"], " ")) ; } Else { $prenom = $ligne ["prenoms"] ; }
 $prenom = StrToUpper (SubStr ($prenom, 0, 1)).StrToLower (SubStr ($prenom, 1, StrLen ($prenom)-1)) ;
 
 Echo "<BODY BACKGROUND=\"../images/fond.png\" TEXT=\"#000000\">" ;

 // Recherche de la note si existe
 $notes = memo_note_texte ($id_utilisateur, $id_eleve, $ligne ["repere1"], $ligne ["repere2"]) ;
 
 $titre_fenetre = "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD WIDTH=\"100%\" ALIGN=\"CENTER\"><FONT COLOR=\"".$theme [0][30]."\">Notes&nbsp;sur&nbsp;l'&eacute;l&egrave;ve&nbsp;".$nom_eleve."&nbsp;<I>".$prenom."</I></FONT></TD>" ;
 $titre_fenetre .= "<TD><A onClick=\"javascript:window.close()\" BORDER=\"0\"><IMG SRC=\"../../images/quitter.png\" BORDER=\"0\"></A></TD></TR></TABLE>" ;
 $non_centrer = 0 ;
 Include ("../include/debut_theme.inc") ;
 Echo "<FORM ACTION=\"./memo_notes.php\" NAME=\"abs_note\" METHOD=\"POST\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"retour\" VALUE=\"".$retour."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_memo_note\" VALUE=\"".$notes [0]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_utilisateur\" VALUE=\"".$id_utilisateur."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_eleve\" VALUE=\"".$id_eleve."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"repere1\" VALUE=\"".$ligne ["repere1"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"repere2\" VALUE=\"".$ligne ["repere2"]."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_service_prof\" VALUE=\"".$id_service_prof."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"eleve\" VALUE=\"".$eleve."\">" ;
 Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"valider\" VALUE=\"VaLiDeR\">" ;
 Echo "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" ALIGN=\"CENTER\">" ;
 Echo "<TR><TD COLSPAN=\"3\" WIDTH=\"".($largeur_memo_edition+50)."\">" ;
 Echo "<TABLE BORDER=\"0\"  WIDTH=\"100%\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"".$theme [0][3]."\" STYLE=\"border-collapse:collapse\">" ;
 Echo "<TR><TD>".active_editeur ($hauteur_memo_edition, $largeur_memo_edition+50, "Simple", $param_theme ["nom_repertoire"], $notes [1])."</TD></TR>" ;
 Echo "</TABLE>" ;
 Echo "</TD></TR>" ;
 Echo "<TR>" ;
 Echo "<TD ALIGN=\"RIGHT\" WIDTH=\"".($largeur_memo_edition/2+30)."\">" ;
 Echo "<INPUT TYPE=\"IMAGE\" SRC=\"".$rep_themes.$param_theme ["nom_repertoire"]."/".$theme [9][0]."\"></TD>" ;
 Echo "</FORM>" ;
 If ($notes [0] > 0)
  {
   Echo "<td align=\"center\"><form action=\"./memo_notes.php\" name=\"abs_note\" method=\"post\" onSubmit=\"return valide()\">" ;
   Echo "<input type=\"hidden\" name=\"retour\" value=\"".$retour."\">" ;
   Echo "<input type=\"hidden\" name=\"id_eleve\" value=\"".$id_eleve."\">" ;
   Echo "<input type=\"hidden\" name=\"id_service_prof\" value=\"".$id_service_prof."\">" ;
   Echo "<input type=\"hidden\" name=\"eleve\" value=\"".$eleve."\">" ;
   Echo "<input type=\"hidden\" name=\"id_memo_note\" value=\"".$notes [0]."\"><input type=\"image\" src=\"".$rep_themes.$param_theme ["nom_repertoire"]."/".$theme [9][2]."\" name=\"valider\" value=\"SuPpRiMeR\"></form></td>" ;
   Echo "<td align=\"right\">" ;
  }
 Else { Echo "<td align=\"right\" colspan=\"2\">" ; }
 Echo "<form><input type=\"image\" src=\"".$rep_themes.$param_theme ["nom_repertoire"]."/".$theme [9][3]."\" NAME=\"annuler\" VALUE=\"AnNuLeR\" onClick=\"javascript:window.close()\"></FORM></TD>" ;
 Echo "</TR></TABLE>" ;
 Include ("../include/fin_theme.inc") ;
 Echo "</BODY>" ;
 Echo "</HTML>" ;
?>